from typing import List, Optional, Dict
from pydantic import BaseModel, Field

class News(BaseModel, frozen=True):
    title: str = Field(
        description=(
            "稿件标题"
        ),
        nullable = False
    )
    reported_on: Optional[str] = Field(
        description=(
            "稿件日期"
        ),
        nullable = False
    )
    cameraman: Optional[List[str]] = Field(
        description="摄像的人名列表，有时候是空，也可能是多个人名",
        nullable = True,
        default=[]
    )
    reporter: Optional[List[str]] = Field(
        description="是记者的人名列表，有时候是空，也可能是多个人名",
        nullable = True,
        default=[]
    )
    voiceover: Optional[List[str]] = Field(
        description="配音的人名列表，有时候是空(包括null或者none)，也可能是多个人名",
        nullable = True,
        default=[]
    )
    content: str = Field(
        description="新闻正文文本，不要转义，也不需要改写内容，完完整整保留原有的文字即可",
        nullable = False
    )

class NER(BaseModel, frozen=True):
    head: str = Field(
        description="head实体名称，必须是人名、地名、活动、事件、角色等名称",
        nullable = False
    )
    tail: str = Field(
        description="tail实体名称，必须是人名、地名、活动、事件、角色等名称",
        nullable = False,
    )
    description: str = Field(
        description="一句话描述head、tail之间的关系，尽量包含更多细节",
        nullable = False,
    )
    occurred_on: Optional[str] = Field(
        description="事件发生日期，采用'yyyy/MM/dd'格式",
        nullable = False,
    )

class NERS(BaseModel):
    entities: Optional[List[NER]] = Field(
        default = [],
        description="{head, tail, description, occurred_on} 四元组集合",
        nullable = False
    )

    @classmethod
    def from_ners(cls, a, b):
        if a.entities is None:
            return b
        elif b.entities is None:
            return a
        else:
            return cls(entities=list(set(a.entities + b.entities)))
